package com.iversonx.bridge.example_1.v3.controller;


import com.iversonx.bridge.example_1.v3.msg.MessageService;
import com.iversonx.bridge.example_1.v3.msg.common.EmailMessageServiceImpl;
import com.iversonx.bridge.example_1.v3.msg.common.MobileMessageServiceImpl;
import com.iversonx.bridge.example_1.v3.msg.common.SMSMessageServiceImpl;
import com.iversonx.bridge.example_1.v3.msg.special.impl.EmailSpecialUrgencyMessageService;
import com.iversonx.bridge.example_1.v3.msg.special.impl.MobileSpecialUrgencyMessageService;
import com.iversonx.bridge.example_1.v3.msg.special.impl.SMSSpecialUrgencyMessageService;
import com.iversonx.bridge.example_1.v3.msg.urgency.impl.EmailUrgencyMessageService;
import com.iversonx.bridge.example_1.v3.msg.urgency.impl.MobileUrgencyMessageService;
import com.iversonx.bridge.example_1.v3.msg.urgency.impl.SMSUrgencyMessageService;

import java.util.ArrayList;
import java.util.List;

/**
 *
 **/
public class MessageControllerV3 {
    private final List<MessageService> messageServiceList;
    private final MessageService defaultMessageService;
    public MessageControllerV3() {
        defaultMessageService = new SMSMessageServiceImpl();
        
        messageServiceList = new ArrayList<>();
        messageServiceList.add(defaultMessageService);
        messageServiceList.add(new SMSUrgencyMessageService());
        messageServiceList.add(new SMSSpecialUrgencyMessageService());
        messageServiceList.add(new EmailMessageServiceImpl());
        messageServiceList.add(new EmailUrgencyMessageService());
        messageServiceList.add(new EmailSpecialUrgencyMessageService());
        messageServiceList.add(new MobileMessageServiceImpl());
        messageServiceList.add(new MobileUrgencyMessageService());
        messageServiceList.add(new MobileSpecialUrgencyMessageService());
    }
    
    
    public void send(String message, String toUser, String type) {
        MessageService messageService = getMessageService(type);
        messageService.send(message, toUser);
    }
    
    public MessageService getMessageService(String type) {
        for(MessageService messageService : messageServiceList) {
            if(messageService.support(type)) {
                return messageService;
            }
        }
        return defaultMessageService;
    }
}
